package ro.gillardon.persistence.document.model;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import ro.gillardon.commons.enums.City;
import ro.gillardon.commons.enums.DayType;
import ro.gillardon.commons.enums.Hotel;
import ro.gillardon.commons.enums.RoomType;
import ro.gillardon.commons.util.DateUtils;

/**
 * Contains methods and details specific to a hotel details (roomType, dayType, price...).
 *
 * @author haiurar
 */
public class HotelDetails extends ODocumentClass {

  private static final String PRICE = "price";
  private static final String DATE = "date";
  private static final String NAME = "name";
  private static final String LOCATION = "location";
  private static final String DAY_TYPE = "dayType";
  private static final String ROOM_TYPE = "roomType";

  /**
   * Instantiates a new hotel details.
   *
   * @param roomType the room type
   * @param dayType the day type
   * @param location the location of the hotel
   * @param name the name of hotel
   * @param date the update date
   * @param price the price of the room
   */
  public HotelDetails(final RoomType roomType, final DayType dayType, final City location,
    final Hotel name, final LocalDateTime date,
    final double price) {
    super();
    this.doc.field(ROOM_TYPE, roomType);
    this.doc.field(DAY_TYPE, dayType);
    this.doc.field(LOCATION, location);
    this.doc.field(NAME, name);
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    this.doc.field(DATE, date.format(formatter));
    this.doc.field(PRICE, price);
  }

  @Override
  public String toString() {
    return "HotelDetails [doc=" + this.doc + "]";
  }

  /**
   * Gets the room type.
   *
   * @return the room type
   */
  public RoomType getRoomType() {
    String roomType = this.doc.field(ROOM_TYPE);
    return RoomType.valueOf(roomType);
  }

  /**
   * Gets the day type.
   *
   * @return the day type
   */
  public DayType getDayType() {
    String dayType = this.doc.field(DAY_TYPE);
    return DayType.valueOf(dayType);
  }

  /**
   * Gets the city in which the hotel is.
   *
   * @return the hotel location
   */
  public City getLocation() {
    String city = this.doc.field(LOCATION);
    return City.valueOf(city);
  }

  /**
   * Gets the name of the hotel.
   *
   * @return name of the hotel
   */
  public Hotel getName() {
    String name = this.doc.field(NAME);
    return Hotel.valueOf(name);
  }

  /**
   * Gets the date of the update.
   *
   * @return the update date
   */
  public LocalDateTime getDate() {
    return DateUtils.convertToLocalDateTime(this.doc.field(DATE));
  }

  /**
   * Gets the price of the room.
   *
   * @return the price of the room
   */
  public double getPrice() {
    return this.doc.field(PRICE);
  }

}
